package cn.e4j.modular.crm.controller;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.core.util.LangUtils;
import cn.e4j.modular.common.service.SysAuthorityService;
import cn.e4j.modular.crm.entity.*;
import cn.e4j.modular.crm.mapper.GwakTMapper;
import cn.e4j.modular.crm.mapper.GwamTMapper;
import cn.e4j.modular.crm.mapper.GwdaTMapper;
import cn.e4j.modular.crm.service.impl.Gwai760ServiceImpl;
import cn.e4j.modular.crm.service.impl.Gwai780ServiceImpl;
import cn.e4j.modular.crm.service.impl.GwdaTServiceImpl;
import cn.e4j.modular.system.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 退货确认单管理
 * Created by shixc on 2019-3-8
 */
@Controller
@RequestMapping("/crm/gwai760")
public class Gwai760Controller extends BaseController {

    @Autowired
    private Gwai760ServiceImpl gwai760Service;

    @Autowired
    private Gwai780ServiceImpl gwai780Service;

    @Autowired
    public SysAuthorityService sysAuthorityService;

    /**
     * 跳转商品经营范围管理页面
     */
    @RequiresPermissions("crm:gwai760:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/gwai760.html";
    }

    /**
     * 查询商品经营范围信息列表
     */
    @RequestMapping("/getList")
    @RequiresPermissions("crm:gwai760:init")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        //客户权限
        inDto.put("CUSTOMERS", sysAuthorityService.getCustomersAuthority(inDto));
        List<Map<String, Object>> result = gwai760Service.getList(page, inDto);
        List<Map<String, Object>> data = gwai760Service.getName(result);
        return new PageReData(page, data);
    }

    /**
     * 批量确认数据
     */
    @RequestMapping("/refund")
    @RequiresPermissions("crm:gwai760:init")
    @ResponseBody
    public ResponseData refund(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Gwai760> gwdaTList = inDto.getReqList(Gwai760.class);
        Dto info = this.gwai780Service.getUser(ShiroKit.getUser().getID());
        gwai760Service.refund(gwdaTList,info);
        return SUCCESS_TIP;
    }

    @RequestMapping("/getListData")
    @ResponseBody
    public ResponseData getListData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwai760Service.getListData(inDto);
        return ResponseData.success(result);
    }
}
